package com.ayi.dao.bookdao;

import com.ayi.utils.CloseConn;
import com.ayi.utils.GetConn;

import java.io.Closeable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 * @author Ayingzz
 * @create 2021/11/28 23:18
 */
public class QueryTypes {

    /**
     * 返回现有图书类型
     * @return
     */
    public Set<String> queryTypes(int queryOrSetting) {
        Connection conn = new GetConn().getConnection();
        String sql = "select * from Books";
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            Set<String> typeSet = new HashSet<>();
            if (queryOrSetting == -1) {
                typeSet.add("全部类型");
            }
            while (rs.next()) {
                typeSet.add(rs.getString("type"));
            }
            return typeSet;
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

}
